//
//  HP_ThwartwiseTypeViewCell.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/8/30.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "HP_ThwartwiseTypeViewCell.h"
#import "HP_ClassifyCollectionViewCell.h"
#import "HP_InstalmentListController.h"
#import "HomePageViewController.h"

@interface HP_ThwartwiseTypeViewCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)NSArray *resultArray;
@end

@implementation HP_ThwartwiseTypeViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initViews];
    }
    return self;
}
-(void)initViews{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.bounces = NO;
    [_collectionView registerClass:[HP_ClassifyCollectionViewCell class] forCellWithReuseIdentifier:@"HP_ClassifyCollectionViewCell"];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(20, 20,20, 20);
    _collectionView.showsHorizontalScrollIndicator = NO;
    [self addSubview:_collectionView];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.top.mas_equalTo(self.mas_top);
        make.bottom.mas_equalTo(self.mas_bottom);
    }];
}
- (void)fillData:(id)data{
    if (!data) {
        return;
    }
    self.resultArray = data;
    [self.collectionView reloadData];
}



-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 4;
//    return _resultArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HP_ClassifyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HP_ClassifyCollectionViewCell" forIndexPath:indexPath];
    
    switch (indexPath.section) {
        case 0:
            cell.iconimageView.image = [UIImage imageNamed:@"home_btn_iphoe"];
            cell.titleLabel.text = @"3C";
            break;
        case 1:
            cell.iconimageView.image = [UIImage imageNamed:@"home_ic_compture"];
            cell.titleLabel.text = @"3E";
            break;
        case 2:
            cell.iconimageView.image = [UIImage imageNamed:@"home_ic_education"];
            cell.titleLabel.text = @"医美";
            break;
        case 3:
            cell.iconimageView.image = [UIImage imageNamed:@"home_ic_driver"];
            cell.titleLabel.text = @"其他";
            break;
            
        default:
            break;
    }
    
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    
    return CGSizeMake(0.1, 157*ScreenWidthMao/375.f);
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    if (ScreenWidthMao< 375) {
//        return CGSizeMake((ScreenWidthMao -12)/ 4.f - 10 - 15, 100*ScreenWidthMao/375.f + 5);
//    }else{
//        return CGSizeMake((ScreenWidthMao -12)/ 4.f - 10 - 15, 100*ScreenWidthMao/375.f);
//    }
    
    return CGSizeMake(ScreenWidthMao/4-0.1, 100*ScreenWidthMao/375.f);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
//    if (section == 0 ) {
//        return UIEdgeInsetsMake(0, 12, 0, 5);
//    }else if (section == self.resultArray.count -1){
//        return UIEdgeInsetsMake(0, 5, 0, 12);
//    }else{
//        return UIEdgeInsetsMake(0, 5, 0, 5);
//    }
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    HP_InstalmentListController *listVC = [[HP_InstalmentListController alloc]init];
    listVC.view.backgroundColor = [UIColor whiteColor];
    HomePageViewController *mainVC = (HomePageViewController *)self.nextResponder.nextResponder.nextResponder .nextResponder.nextResponder.nextResponder;
    [mainVC.navigationController pushViewController:listVC animated:YES];
}

+(CGSize)calculateSize:(id)data{
//    if(!data || ![data isKindOfClass:[NSArray class]]) {
//        return CGSizeMake(0, 0);
//    }
    return CGSizeMake(ScreenWidthMao, 100*ScreenWidthMao/375.f);
}

@end
